package com.project.config;

import com.project.interceptor.CustomInterceptor;
import com.project.interceptor.ManagerInterceptor;
import com.project.interceptor.SendInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MVCConfig implements WebMvcConfigurer {
    @Autowired
    private CustomInterceptor customInterceptor;
    @Autowired
    private SendInterceptor sendInterceptor;
    @Autowired
    private ManagerInterceptor managerInterceptor;

    @Override  //拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration customReg = registry.addInterceptor(customInterceptor);
        customReg.addPathPatterns("/customer/**");
        InterceptorRegistration sendReg = registry.addInterceptor(sendInterceptor);
        sendReg.addPathPatterns("/send/**");
        InterceptorRegistration managerReg = registry.addInterceptor(managerInterceptor);
        managerReg.addPathPatterns("/manager/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/productImg/**").addResourceLocations("file:D:/shopCartSys/productImg/");
    }

}
